home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ARASAN_S.ZIP / HINT.CPP < prev    next >
C/C++ Source or Header  |  1994-02-25  |  2KB  |  71 lines

  1. // Copyright 1993 by Jon Dart.  All Rights Reserved.
  2.  
  3. #include "hint.h"
  4. #include "search.h"
  5. #include "globals.h"
  6. #include "notation.h"
  7. #include "util.h"
  8.  
  9. Move HintDialog::hintMove;
  10.  
  11. HintDialog::HintDialog(WPWin *pwin, Board &board) :
  12.   WPDialogModal("Hint", pwin, NULL, NULL),
  13.   the_board(board),
  14.   parent(pwin),
  15.   next_move(0),
  16.   num_moves(0)
  17. {
  18.    createWin();
  19. }
  20.  
  21. void HintDialog::initDlg()
  22. {
  23.      const HWND hDlg = getHwnd();
  24.      move_text = GetDlgItem(hDlg,IDP_HINT_TEXT);
  25.      compute_hint();
  26. }
  27.  
  28. void HintDialog::compute_hint()
  29. {
  30.     // we keep a list of the hint moves generated so far.
  31.     if (!moves[next_move].IsNull())
  32.     {
  33.         hintMove = moves[next_move];
  34.     }
  35.     else
  36.     {    
  37.         WPWaitCursor wait = parent;
  38.         num_moves = opening_book->book_moves(the_board,moves,
  39.             Constants::MAX_HINT_MOVES);
  40.         if (!num_moves)
  41.         {
  42.         // no book move, must search:
  43.         Search searcher;
  44.             num_moves = searcher.hints(the_board,moves,
  45.             Constants::MAX_HINT_MOVES);
  46.         }
  47.         hintMove = moves[0];
  48.     }
  49.     if (!hintMove.IsNull())
  50.     {
  51.         char result[20];
  52.     Notation::Image(the_board,hintMove,result);
  53.         SetWindowText(move_text,result);
  54.     ++next_move;
  55.     if (next_move >= num_moves) next_move = 0;
  56.     }
  57. }
  58.  
  59. BOOL HintDialog::command(int id, WORD msg)
  60. {
  61.    switch (id) 
  62.    {
  63.    case IDP_ANOTHER:
  64.      compute_hint();
  65.      return TRUE;
  66.    default:
  67.      break;
  68.    }
  69.    return WPDialogModal::command(id, msg); 
  70. }
  71.